<!DOCTYPE html>
<html lang=zh-CN>
<head>
<meta charset=utf-8>
<title>JSHint配置参数详解 | Cweili Beta</title>
<meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name=description content="JSHint 是 Javascript 代码验证工具，可以检查你的代码并提供相关的代码改进意见。使用 JSHint 时，发现这个家伙配置参数众多，实在有乱花迷眼之势，故记录此处。">
<meta property=og:type content=article>
<meta property=og:title content=JSHint配置参数详解>
<meta property=og:url content="http://cweili.gitcafe.com/jshint-options/">
<meta property=og:site_name content="Cweili Beta">
<meta property=og:description content="JSHint 是 Javascript 代码验证工具，可以检查你的代码并提供相关的代码改进意见。使用 JSHint 时，发现这个家伙配置参数众多，实在有乱花迷眼之势，故记录此处。">
<meta name=twitter:card content=summary>
<meta name=twitter:title content=JSHint配置参数详解>
<meta name=twitter:description content="JSHint 是 Javascript 代码验证工具，可以检查你的代码并提供相关的代码改进意见。使用 JSHint 时，发现这个家伙配置参数众多，实在有乱花迷眼之势，故记录此处。">
<link rel=alternative href=/atom.xml title="Cweili Beta" type=application/atom+xml>
<link rel=icon href=favicon.png>
<link rel=stylesheet href=//libs.baidu.com/bootstrap/3.2.0/css/bootstrap.min.css type=text/css>
<link rel=stylesheet href=../css/style.css type=text/css>
<!--[if lt IE 9]><script src="//cdn.staticfile.org/html5shiv/3.7/html5shiv.min.js" type="text/javascript"></script><![endif]-->
</head>
<body>
<div id=container>
<nav id=mobile-nav class=visible-xs>
<a href="/" class=mobile-nav-link>首页</a>
<ul class=category-list><li class=category-list-item><a class=category-list-link href=../category/学习笔记>学习笔记</a><span class=category-list-count>40</span></li><li class=category-list-item><a class=category-list-link href=../category/小生活>小生活</a><span class=category-list-count>27</span></li><li class=category-list-item><a class=category-list-link href=../category/杂物>杂物</a><span class=category-list-count>9</span></li></ul>
<a href="/tag/%E7%9B%B8%E5%86%8C/" class=mobile-nav-link>相册</a>
<a href="/about/" class=mobile-nav-link>关于</a>
<div class=clearfix></div>
</nav>
<div id=wrap>
<!--[if lt IE 9]><p class="browsehappy alert alert-danger">您正在使用一个<strong>过时</strong>的浏览器。请<a href="http://browsehappy.com/" target="_blank">更新您的浏览器</a>来达到更好的体验。</p><![endif]-->
<header id=header>
<div id=banner></div>
<div id=header-outer class=outer>
<div id=header-inner class=inner>
<nav class=main-nav>
<div id=main-nav-toggle class="nav-icon visible-xs"><i class="fa fa-bars"></i></div>
<a class="main-nav-link hidden-xs" href="/">首页</a>
</nav>
<nav id=category-nav class=hidden-xs>
<ul class=category-list><li class=category-list-item><a class=category-list-link href=../category/学习笔记>学习笔记</a><span class=category-list-count>40</span></li><li class=category-list-item><a class=category-list-link href=../category/小生活>小生活</a><span class=category-list-count>27</span></li><li class=category-list-item><a class=category-list-link href=../category/杂物>杂物</a><span class=category-list-count>9</span></li></ul>
</nav>
<nav class="main-nav hidden-xs">
<a class=main-nav-link href="/tag/%E7%9B%B8%E5%86%8C/">相册</a>
<a class=main-nav-link href="/about/">关于</a>
</nav>
<nav id=sub-nav>
<a id=nav-rss-link class="nav-icon pull-right hidden-xs" href=/atom.xml title="RSS 订阅"><i class="fa fa-rss"></i></a>
<div id=nav-search-btn class="nav-icon pull-right" title=搜索><i class="fa fa-search"></i></div>
</nav>
<div id=search-form-wrap>
<form action=http://www.baidu.com/baidu accept-charset=utf-8 class=search-form target=_blank>
<input type=search name=word class=search-form-input placeholder=搜索>
<input id=search-form-submit type=submit value=&nbsp; class=search-form-submit>
<input name=tn type=hidden value=bds>
<input name=cl type=hidden value=3>
<input name=ct type=hidden value=2097152>
<input type=hidden name=si value=cweili.gitcafe.com>
<label class=search-form-submit for=search-form-submit><i class="fa fa-search"></i></label>
</form>
</div>
</div>
<div id=header-title class=inner>
<h1 id=logo-wrap>
<a href="/" id=logo>Cweili Beta</a>
</h1>
<h2 id=subtitle-wrap>
<a href="/" id=subtitle>I&#39;m working on it</a>
</h2>
</div>
</div>
</header>
<div class=outer>
<section id=main class=col-sm-9><article id=post-jshint-options class="article article-type-post" itemscope itemprop=blogPost>
<div class=article-meta>
<a href="/jshint-options/" class=article-date>
<time datetime=2014-08-14T03:16:32.000Z itemprop=datePublished>2014-08-14</time>
</a>
<div class=article-category>
<a class=article-category-link href=../category/学习笔记>学习笔记</a>
</div>
</div>
<div class="article-inner jiathis_streak">
<header class=article-header>
<h2 class=article-title itemprop=name>
JSHint配置参数详解
</h2>
</header>
<div class=article-entry itemprop=articleBody>
<blockquote>
<p>JSHint 是 Javascript 代码验证工具，可以检查你的代码并提供相关的代码改进意见。<br>使用 JSHint 时，发现这个家伙配置参数众多，实在有乱花迷眼之势，故记录此处。<br><a id=more></a></p>
</blockquote>
<h4 id="增强参数 (Enforcing_Options)"> 增强参数(Enforcing Options)</h4>
<hr>
<p>本类参数设为<code>true</code>，JSHint 会产生更多告警。</p>
<ul>
<li><strong>bitwise</strong></li>
</ul>
<p>禁用位运算符(如<code>^</code>，<code>|</code>，<code>&amp;</code>)</p>
<p>位运算符在 JS 中很少使用，性能也较差，出现 <code>&amp;</code> 也很可能是想写<code>&amp;&amp;</code>。</p>
<ul>
<li><strong>camelcase</strong></li>
</ul>
<p>使用驼峰命名 (<code>camelCase</code>) 或全大写下划线命名(<code>UPPER_CASE</code>)</p>
<p>这是条 <em> 最佳实践</em>，关键不在于采用什么样的命名规则(比如纯小写配下划线)，而在于要有规则，在代码中看到不同的命名规则会让人头痛不已。</p>
<ul>
<li><strong>curly</strong></li>
</ul>
<p><code>if</code>和 <code>while</code> 等语句中使用 <code>{}</code> 来明确代码块，虽然缩进表示两条语句都在循环中，但事实却是只有一句循环。</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div><div class=line>2</div><div class=line>3</div></pre></td><td class=code><pre><div class=line><span class=keyword>while</span> (day)</div><div class=line>    shuffle();</div><div class=line>    sleep();</div></pre></td></tr></table></figure>
<ul>
<li><strong>eqeqeq</strong></li>
</ul>
<p>使用 <code>===</code> 和<code>!==</code>替代 <code>==</code> 和<code>!=</code></p>
<p><code>==</code>和 <code>!=</code> 比较时会对前后元素进行自动转义，作为读者，需要动脑筋想这里可能有什么样的转义规则，加重负担；作为作者，其实很可能是不确定这段代码运行时是怎么样的，想要偷懒。</p>
<ul>
<li><strong>es3</strong></li>
</ul>
<p>强制使用 ECMAScript 3 规范</p>
<ul>
<li><strong>forin</strong></li>
</ul>
<p>在 <code>for in</code> 循环中使用 <code>Object.prototype.hasOwnProperty()</code> 来过滤原型链中的属性，<code>for in</code>遍历对象属性的时候，包括继承自原型链的属性，<code>hasOwnProperty</code>可以来判断一个属性是否是对象本身的属性而不是继承得来的。</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div><div class=line>2</div><div class=line>3</div><div class=line>4</div><div class=line>5</div></pre></td><td class=code><pre><div class=line><span class=keyword>for</span> (key <span class=keyword>in</span> obj) {</div><div class=line>    <span class=keyword>if</span> (obj.hasOwnProperty(key)) {</div><div class=line>    <span class=comment>// We are sure that obj[key] belongs to the object and was not inherieted.</span></div><div class=line>    }</div><div class=line>}</div></pre></td></tr></table></figure>
<ul>
<li><strong>freeze</strong></li>
</ul>
<p>禁止复写原生对象 (如<code>Array</code>, <code>Date</code>) 的原型</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div><div class=line>2</div><div class=line>3</div></pre></td><td class=code><pre><div class=line><span class=comment>/* jshint freeze:true */</span></div><div class=line><span class=built_in>Array</span>.prototype.count = <span class=function><span class=keyword>function</span> <span class=params>(value)</span> </span>{<span class=keyword>return</span> <span class=number>4</span>; };</div><div class=line><span class=comment>// -&gt; Warning: Extending prototype of native object: 'Array'.</span></div></pre></td></tr></table></figure>
<p>为原生对象添加属性确实看上去很方便，但也带来了潜在的问题，一是如果项目中有多处为同一个对象添加了同样的属性（或函数），则很可能产生冲突；二是如果某段逻辑依赖于对象属性遍历，则可能产生错误。</p>
<ul>
<li><strong>immed</strong></li>
</ul>
<p>匿名函数调用必须</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div><div class=line>2</div><div class=line>3</div></pre></td><td class=code><pre><div class=line>(<span class=function><span class=keyword>function</span><span class=params>()</span> </span>{</div><div class=line>   <span class=comment>// body </span></div><div class=line>}());</div></pre></td></tr></table></figure>
<p>而不是</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div><div class=line>2</div><div class=line>3</div></pre></td><td class=code><pre><div class=line>(<span class=function><span class=keyword>function</span><span class=params>()</span> </span>{</div><div class=line>   <span class=comment>// body</span></div><div class=line>})();</div></pre></td></tr></table></figure>
<p>这是为了表明，表达式的值是函数的结果，而不是函数本身。</p>
<ul>
<li><strong>indent</strong></li>
</ul>
<p>代码缩进宽度（空格数）</p>
<p>前面几个项目我比较喜欢 4，新项目我又在尝试 2。关键不在于是几，而在于大家都要设成一样的。</p>
<ul>
<li><strong>latedef</strong></li>
</ul>
<p>变量定义前禁止使用</p>
<p>JS 的变量是“函数级作用域”，而不是通常所见的“块级作用域”，简单说</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div><div class=line>2</div><div class=line>3</div><div class=line>4</div><div class=line>5</div><div class=line>6</div><div class=line>7</div></pre></td><td class=code><pre><div class=line><span class=function><span class=keyword>function</span> <span class=title>sum</span><span class=params>(numbers)</span> </span>{</div><div class=line>    <span class=keyword>for</span> (<span class=keyword>var</span> i = <span class=number>0</span>, n = numbers.length; i &lt; n; i++) {</div><div class=line>        <span class=keyword>var</span> sum = sum + numbers[i];</div><div class=line>    }</div><div class=line></div><div class=line>    <span class=keyword>return</span> sum;</div><div class=line>}</div></pre></td></tr></table></figure>
<p>相当于</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div><div class=line>2</div><div class=line>3</div><div class=line>4</div><div class=line>5</div><div class=line>6</div><div class=line>7</div><div class=line>8</div><div class=line>9</div></pre></td><td class=code><pre><div class=line><span class=function><span class=keyword>function</span> <span class=title>sum</span><span class=params>(numbers)</span> </span>{</div><div class=line>    <span class=keyword>var</span> i, n, sum;</div><div class=line></div><div class=line>    <span class=keyword>for</span> (i = <span class=number>0</span>, n = numbers.length; i &lt; n; i++) {</div><div class=line>       sum = sum + numbers[i];</div><div class=line>    }</div><div class=line></div><div class=line>    <span class=keyword>return</span> sum;</div><div class=line>}</div></pre></td></tr></table></figure>
<p>这个行为叫做“变量声明提升”，为了不产生混淆，这条规则建议函数都使用第二种写法。</p>
<ul>
<li><strong>newcap</strong></li>
</ul>
<p>构造函数名首字母必须大写</p>
<p>这条 <em> 最佳实践 </em> 是为了方便区分构造函数和普通函数，这样在直接调用大写字母开头的函数时，使用者就会想想是不是自己写错了。</p>
<p>不通过 <code>new</code> 而直接调用构造函数，会使得构造函数中的 <code>this</code> 指向 <code>global</code> 对象，从而产生错误。</p>
<p>PS. 有些高手可以通过在构造函数中判断 <code>this</code> 的指向来判断是否重新 <code>new</code> 自身，从而让构造函数也能直接调用产生新对象。但这有些高深，加重开发人员和使用人员的负担，也不利于统一编码风格。</p>
<ul>
<li><strong>noarg</strong></li>
</ul>
<p>禁止使用 <code>arguments.caller</code> 和<code>arguments.callee</code></p>
<p>一方面这两个属性不是所有的浏览器都支持，另一方面这两个属性的使用会导致 JS 引擎很难优化代码，在未来的 JS 规范中会被去掉，所以不建议使用。</p>
<ul>
<li><strong>noempty</strong></li>
</ul>
<p>禁止出现空的代码块</p>
<p>空的代码块并不是有害的，但是出现的话我们需要考虑下为什么。</p>
<ul>
<li><strong>nonbsp</strong></li>
</ul>
<p>禁止”non-breaking whitespace”</p>
<p>这是 Mac 键盘在某种情况下可以键入的字符，据说会破坏非 UTF8 编码的页面。</p>
<ul>
<li><strong>nonew</strong></li>
</ul>
<p>禁止使用构造器</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div></pre></td><td class=code><pre><div class=line><span class=keyword>new</span> MyConstructor();</div></pre></td></tr></table></figure>
<p>构造一个对象，却不给它赋值到某个变量，只是利用构造函数中的逻辑。这个行为完全可以用一个普通函数来完成，不应该借助构造器。</p>
<ul>
<li><strong>plusplus</strong></li>
</ul>
<p>禁止使用 <code>++</code> 和<code>--</code></p>
<p>不是很赞成把这个选项打成<code>true</code>，不过乱用自增 / 自减确实也会带来阅读上的障碍。</p>
<ul>
<li><strong>quotemark</strong></li>
</ul>
<p>统一使用单引号或双引号</p>
<p>这个 <em> 最佳实践 </em> 要求代码风格统一，我比较喜欢统一成单引号。</p>
<p>这是为什么规定 <em> 最佳实践 </em> 的一个好例子，在写到字符串的时候我们就不用考虑使用单引号好还是用双引号好，就都用单引号，这在一定程度上也减轻了我们的思考负担。</p>
<ul>
<li><strong>undef</strong></li>
</ul>
<p>禁止使用不在全局变量列表中的未定义的变量</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div><div class=line>2</div><div class=line>3</div><div class=line>4</div></pre></td><td class=code><pre><div class=line><span class=function><span class=keyword>function</span> <span class=title>test</span><span class=params>()</span> </span>{</div><div class=line>    <span class=keyword>var</span> myVar = <span class=string>'Hello, World'</span>;</div><div class=line>    <span class=built_in>console</span>.log(myvar); <span class=comment>// Oops, typoed here. JSHint with undef will complain</span></div><div class=line>}</div></pre></td></tr></table></figure>
<p>如果本地作用域里的变量没有使用 var 来声明，则会被放到全局作用域下面，众所周知，全局变量时罪恶的源泉。</p>
<ul>
<li><strong>unused</strong></li>
</ul>
<p>禁止定义变量却不使用</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div><div class=line>2</div><div class=line>3</div><div class=line>4</div><div class=line>5</div><div class=line>6</div><div class=line>7</div></pre></td><td class=code><pre><div class=line><span class=function><span class=keyword>function</span> <span class=title>test</span><span class=params>(a, b)</span> </span>{</div><div class=line>    <span class=keyword>var</span> c, d = <span class=number>2</span>;</div><div class=line>    <span class=keyword>return</span> a + d;</div><div class=line>}</div><div class=line>test(<span class=number>1</span>, <span class=number>2</span>);</div><div class=line><span class=comment>// Line 1: 'b' was defined but never used.</span></div><div class=line><span class=comment>// Line 2: 'c' was defined but never used.</span></div></pre></td></tr></table></figure>
<p>这种变量通常是写作过程中遗留下来的垃圾，需要及时清理掉。</p>
<ul>
<li><strong>strict</strong></li>
</ul>
<p>强制使用 ES5 的严格模式</p>
<p>Strict Mode 是对 JS 用法的一些限制，过滤掉了容易出错的特性和不容易优化的特性。</p>
<p>通过在函数开头处加入<code>&#39;use strict&#39;</code>; 来触发严格模式，不要在文件头部加入，因为在 JS 链接的时候很可能就失效了。</p>
<ul>
<li><strong>trailing</strong></li>
</ul>
<p>禁止行尾空格</p>
<ul>
<li><strong>maxparams</strong></li>
</ul>
<p>函数可以接受的最大参数数量</p>
<p>函数参数数量应该控制在 3 个以内，超出则可能造成使用困难，比如需要记忆参数顺序，难以设定默认值等。另外，在 JS 中可以很方便的使用参数对象来封装多个参数。</p>
<ul>
<li><strong>maxdepth</strong></li>
</ul>
<p>代码块中可以嵌入 {} 的最大深度</p>
<ul>
<li><strong>maxstatement</strong></li>
</ul>
<p>函数中最大语句数</p>
<ul>
<li><strong>maxcomplexity</strong></li>
</ul>
<p>函数的最大圈复杂度</p>
<ul>
<li><strong>maxlen</strong></li>
</ul>
<p>一行中最大字符数</p>
<p>这个是为了减轻代码阅读的困难，简单说就是不要折行。</p>
<p>上面四个参数最终都是为了减小代码的复杂程度，简单轻巧的代码片段更容易阅读和维护。</p>
<h4 id="松弛参数 (Relaxing_Options)"> 松弛参数(Relaxing Options)</h4>
<hr>
<p>本类参数设为<code>true</code>，JSHint 会产生更少告警。</p>
<ul>
<li><strong>asi</strong></li>
</ul>
<p>允许省略分号</p>
<p>JavaScript 的语法允许自动补全分号，但是这一特性也会造成难以定位的错误，所以建议写代码时不要省略分号。</p>
<ul>
<li><strong>boss</strong></li>
</ul>
<p>允许在 <code>if</code>，<code>for</code>，<code>while</code> 语句中使用赋值</p>
<p>在条件语句中使用赋值经常是笔误 <code>if (a = 10) {}</code>，但是牛人(boss) 可以把这个特性用的很好，我们作为普通人就算了。</p>
<ul>
<li><strong>debug</strong></li>
</ul>
<p>允许 debugger 语句</p>
<p>debugger 语句在产品代码中应该去掉。</p>
<ul>
<li><strong>eqnull</strong></li>
</ul>
<p>允许<code>==null</code></p>
<p><code>==null</code>通常用来比较<code>=== null || === undefined</code></p>
<ul>
<li><strong>esnext</strong></li>
</ul>
<p>允许 ECMAScript 6 规约</p>
<p>目前 ES6 的特性不是所有的浏览器都支持。</p>
<ul>
<li><strong>evil</strong></li>
</ul>
<p>允许使用 eval</p>
<p>eval 有“注入攻击”的危险，另一方面也不利于 JS 引擎优化代码，所以尽量不要使用。</p>
<ul>
<li><strong>expr</strong></li>
</ul>
<p>允许应该出现赋值或函数调用的地方使用表达式</p>
<ul>
<li><strong>funcscope</strong></li>
</ul>
<p>允许在控制体内定义变量而在外部使用</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div><div class=line>2</div><div class=line>3</div><div class=line>4</div><div class=line>5</div><div class=line>6</div><div class=line>7</div><div class=line>8</div></pre></td><td class=code><pre><div class=line><span class=function><span class=keyword>function</span> <span class=title>test</span><span class=params>()</span> </span>{</div><div class=line>    <span class=keyword>if</span> (<span class=literal>true</span>) {</div><div class=line>        <span class=keyword>var</span> x = <span class=number>0</span>;</div><div class=line>    }</div><div class=line></div><div class=line>    x += <span class=number>1</span>; <span class=comment>// Default: 'x' used out of scope.</span></div><div class=line>            <span class=comment>// No warning when funcscope:true</span></div><div class=line>}</div></pre></td></tr></table></figure>
<p>虽然“变量声明提升”使得上面的代码可以运行通过，但是读者还是会感到头晕。</p>
<ul>
<li><strong>globalstrict</strong></li>
</ul>
<p>允许全局严格模式</p>
<p>在 <strong>strict</strong> 中解释了，<code>&#39;use strict&#39;;</code>放在全局域可能造成 JS 文件链接错误。</p>
<ul>
<li><strong>iterator</strong></li>
</ul>
<p>允许<code>__iterator__</code></p>
<p>不是所有的浏览器都支持<code>__iterator__</code>。</p>
<ul>
<li><strong>lastsemic</strong></li>
</ul>
<p>允许单行控制块省略分号</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div></pre></td><td class=code><pre><div class=line><span class=keyword>var</span> name = (<span class=function><span class=keyword>function</span><span class=params>()</span> </span>{<span class=keyword>return</span> <span class=string>'Anton'</span> }());</div></pre></td></tr></table></figure>
<p>高手用得到的特性，我们还是坚持加上分号吧。</p>
<ul>
<li><strong>laxbreak</strong></li>
</ul>
<p>允许不安全的行中断 (与<strong>laxcomma</strong> 配合使用)</p>
<ul>
<li><strong>laxcomma</strong></li>
</ul>
<p>允许逗号开头的编码样式</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div><div class=line>2</div><div class=line>3</div><div class=line>4</div><div class=line>5</div></pre></td><td class=code><pre><div class=line><span class=keyword>var</span> obj = {</div><div class=line>    name: <span class=string>'Anton'</span></div><div class=line>  , handle: <span class=string>'valueof'</span></div><div class=line>  , role: <span class=string>'SW Engineer'</span></div><div class=line>};</div></pre></td></tr></table></figure>
<ul>
<li><strong>loopfunc</strong></li>
</ul>
<p>允许循环中定义函数</p>
<p>在循环中定义函数经常会导致错误：</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div><div class=line>2</div><div class=line>3</div><div class=line>4</div><div class=line>5</div><div class=line>6</div><div class=line>7</div><div class=line>8</div><div class=line>9</div></pre></td><td class=code><pre><div class=line><span class=keyword>var</span> nums = [];</div><div class=line></div><div class=line><span class=keyword>for</span> (<span class=keyword>var</span> i = <span class=number>0</span>; i &lt; <span class=number>10</span>; i++) {</div><div class=line>    nums[i] = <span class=function><span class=keyword>function</span> <span class=params>(j)</span> </span>{</div><div class=line>        <span class=keyword>return</span> i + j;</div><div class=line>    };</div><div class=line>}</div><div class=line></div><div class=line>nums[<span class=number>0</span>](<span class=number>2</span>); <span class=comment>// Prints 12 instead of 2</span></div></pre></td></tr></table></figure>
<p>错误的根源在于 <code>function(j)</code> 中的 <code>i</code> 是对循环中的 i 的引用，而不是赋值。所以在最终函数执行时，<code>i</code>的值是<code>10</code>。</p>
<p>修改的方法是使用闭包：</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div><div class=line>2</div><div class=line>3</div><div class=line>4</div><div class=line>5</div><div class=line>6</div><div class=line>7</div><div class=line>8</div><div class=line>9</div></pre></td><td class=code><pre><div class=line><span class=keyword>var</span> nums = [];</div><div class=line></div><div class=line><span class=keyword>for</span> (<span class=keyword>var</span> i = <span class=number>0</span>; i &lt; <span class=number>10</span>; i++) {</div><div class=line>    (<span class=function><span class=keyword>function</span> <span class=params>(i)</span> </span>{</div><div class=line>        nums[i] = <span class=function><span class=keyword>function</span> <span class=params>(j)</span> </span>{</div><div class=line>            <span class=keyword>return</span> i + j;</div><div class=line>        };</div><div class=line>    }(i));</div><div class=line>}</div></pre></td></tr></table></figure>
<ul>
<li><strong>maxerr</strong></li>
</ul>
<p>JSHint 中断扫描前允许的最大错误数</p>
<p>因为最终我们需要清零 JSHint 报错的，所以这个值用在对已有项目的扫描中。</p>
<ul>
<li><strong>multistr</strong></li>
</ul>
<p>允许多行字符串</p>
<ul>
<li><strong>notypeof</strong></li>
</ul>
<p>允许非法的 <code>typeof</code> 操作</p>
<ul>
<li><strong>proto</strong></li>
</ul>
<p>允许<code>__proto__</code></p>
<p>不是所有的浏览器都支持<code>__proto__</code>.</p>
<ul>
<li><strong>smarttabs</strong></li>
</ul>
<p>允许混合 tab 和 space 排版</p>
<p>SmartTabs 方法使用 tab 进行缩进，使用空格进行代码对齐。比较高级的用法，有兴趣的话可以尝试下。</p>
<ul>
<li><strong>shadow</strong></li>
</ul>
<p>允许变量 shadow</p>
<figure class="highlight js"><table><tr><td class=gutter><pre><div class=line>1</div><div class=line>2</div><div class=line>3</div><div class=line>4</div><div class=line>5</div><div class=line>6</div><div class=line>7</div><div class=line>8</div><div class=line>9</div></pre></td><td class=code><pre><div class=line><span class=function><span class=keyword>function</span> <span class=title>test</span><span class=params>()</span> </span>{</div><div class=line>    <span class=keyword>var</span> x = <span class=number>10</span>;</div><div class=line></div><div class=line>    <span class=keyword>if</span> (<span class=literal>true</span>) {</div><div class=line>        <span class=keyword>var</span> x = <span class=number>20</span>;</div><div class=line>    }</div><div class=line></div><div class=line>    <span class=keyword>return</span> x;</div><div class=line>}</div></pre></td></tr></table></figure>
<p>基于“函数作用域”，多次定义变量和单次定义是没有区别的，但是会造成阅读障碍。</p>
<ul>
<li><strong>sub</strong></li>
</ul>
<p>允许 person[‘name’]</p>
<p>JSHint 推荐使用 <code>person.name</code> 代替<code>person[&#39;name&#39;]</code></p>
<ul>
<li><strong>supernew</strong></li>
</ul>
<p>允许 <code>new function() {...}</code> 和<code>new Object</code>;</p>
<ul>
<li><strong>validthis</strong></li>
</ul>
<p>允许严格模式下在非构造函数中使用<code>this</code></p>
<ul>
<li><strong>noyield</strong></li>
</ul>
<p>允许发生器中没有 yield 语句</p>
<h4 id="环境参数 (Enviroments)"> 环境参数(Enviroments)</h4>
<hr>
<p>预定义一些全局变量，如 node 等，就不再展开了。</p>
<p>感谢：<a href="http://corncandy.github.io/2014/05/31/jshint-options/" target=_blank rel=external>原文</a></p>
<div class=ujian-hook></div>
</div>
<footer class=article-footer>
<div class=bdsharebuttonbox>
<a href=# class=bds_tsina data-cmd=tsina title=分享到新浪微博></a>
<a href=# class=bds_qzone data-cmd=qzone title=分享到QQ空间></a>
<a href=# class=bds_tqq data-cmd=tqq title=分享到腾讯微博></a>
<a href=# class=bds_weixin data-cmd=weixin title=分享到微信></a>
<a href=# class=bds_tieba data-cmd=tieba title=分享到百度贴吧></a>
<a href=# class=bds_renren data-cmd=renren title=分享到人人网></a>
<a href=# class=bds_tqf data-cmd=tqf title=分享到腾讯朋友></a>
<a href=# class=bds_douban data-cmd=douban title=分享到豆瓣网></a>
<a href=# class=bds_tsohu data-cmd=tsohu title=分享到搜狐微博></a>
<a href=# class=bds_t163 data-cmd=t163 title=分享到网易微博></a>
<a href=# class=bds_taobao data-cmd=taobao title=分享到我的淘宝></a>
<a href=# class=bds_fx data-cmd=fx title=分享到飞信></a>
<a href=# class=bds_hi data-cmd=hi title=分享到百度空间></a>
<a href=# class=bds_more data-cmd=more></a>
</div>
<ul class=article-tag-list><li class=article-tag-list-item><a class=article-tag-list-link href=../tag/jshint>JSHint</a></li><li class=article-tag-list-item><a class=article-tag-list-link href=../tag/javascript>JavaScript</a></li></ul>
</footer>
</div>
<nav id=article-nav>
<a href="/stu3-zoo/" id=article-nav-newer class=article-nav-link-wrap>
<strong class=article-nav-caption>Newer</strong>
<div class=article-nav-title>
Stu3 Zoo
</div>
</a>
<a href="/css3-jquery-rocket-to-top/" id=article-nav-older class=article-nav-link-wrap>
<strong class=article-nav-caption>Older</strong>
<div class=article-nav-title>CSS3动画与jQuery实现返回顶部小火箭</div>
</a>
</nav>
</article>
<section id=comments>
<div class=ds-thread data-thread-key="jshint-options/" data-title=JSHint配置参数详解 data-url="http://cweili.gitcafe.com/jshint-options/"></div>
</section>
</section>
<aside id=sidebar class=col-sm-3>
<div class="widget-wrap hidden-xs">
<h3 class=widget-title>分类</h3>
<div class=widget>
<ul class=category-list><li class=category-list-item><a class=category-list-link href=../category/学习笔记>学习笔记</a><span class=category-list-count>40</span></li><li class=category-list-item><a class=category-list-link href=../category/小生活>小生活</a><span class=category-list-count>27</span></li><li class=category-list-item><a class=category-list-link href=../category/杂物>杂物</a><span class=category-list-count>9</span></li></ul>
</div>
</div>
<div class=widget-wrap>
<h3 class=widget-title>最新评论</h3>
<div class=widget>
<div class=ds-recent-comments data-num-items=10 data-show-avatars=1 data-show-time=1 data-show-title=0 data-show-admin=1 data-excerpt-length=20>
<div class=text-center><i class="fa fa-refresh fa-spin"></i></div>
</div>
</div>
</div>
<div class=widget-wrap>
<h3 class=widget-title>最新文章</h3>
<div class=widget>
<ul>
<li>
<a href="/xixishidi/">河塘飞鸟西溪湿地</a>
</li>
<li>
<a href="/xizihu/">水光潋滟西子湖畔</a>
</li>
<li>
<a href="/xitang/">柳絮纷飞烟雨西塘</a>
</li>
<li>
<a href="/wuzhen/">灯火阑珊水映乌镇</a>
</li>
<li>
<a href="/stu3-zoo/">Stu3 Zoo</a>
</li>
<li>
<a href="/jshint-options/">JSHint配置参数详解</a>
</li>
<li>
<a href="/css3-jquery-rocket-to-top/">CSS3动画与jQuery实现返回顶部小火箭</a>
</li>
<li>
<a href="/rebuild-blog-gitcafe/">再一次重建我的博客</a>
</li>
<li>
<a href="/java-poi-excel/">Java使用POI创建Excel图表</a>
</li>
<li>
<a href="/hibernate-connect-sqlite-paging-bug-repair/">Hibernate 连接 SQLite (hibernate-sqlite) 分页bug的修复</a>
</li>
<li>
<a href="/web-page-color-chart/">更全的网页颜色表</a>
</li>
<li>
<a href="/quarrying-rocky-4/">20120407春游采石矶(四)</a>
</li>
<li>
<a href="/quarrying-rocky-3/">20120407春游采石矶(三)</a>
</li>
<li>
<a href="/quarrying-rocky-2/">20120407春游采石矶(二)</a>
</li>
<li>
<a href="/quarrying-rocky/">20120407春游采石矶(一)</a>
</li>
<li>
<a href="/ahpu-spring/">安徽工程大学的春天</a>
</li>
<li>
<a href="/helps-students-assembled-computer/">帮同学组装帅气小机箱电脑一台</a>
</li>
<li>
<a href="/nanjing-trip-4/">20120310南京二日行(四)</a>
</li>
<li>
<a href="/nanjing-trip-3/">20120310南京二日行(三)</a>
</li>
<li>
<a href="/nanjing-trip-2/">20120310南京二日行(二)</a>
</li>
</ul>
</div>
</div>
<div class="widget-wrap hidden-xs">
<h3 class=widget-title>手机阅读</h3>
<div class=widget>
<div class=qrcode style="background-image:url(http://qr.liantu.com/api.php?bg=eeeeee&fg=000000&el=l&w=192&m=0&text=http://cweili.gitcafe.com/jshint-options/)"></div>
</div>
</div>
<div class="widget-wrap hidden-xs">
<h3 class=widget-title>标签云</h3>
<div class="widget tagcloud">
<a href=../tag/acm style=font-size:10px>ACM</a><a href=../tag/c++ style=font-size:15.71px>C++</a><a href=../tag/css style=font-size:10px>CSS</a><a href=../tag/fedora style=font-size:15.71px>Fedora</a><a href=../tag/gnome style=font-size:11.43px>Gnome</a><a href=../tag/hibernate style=font-size:10px>Hibernate</a><a href=../tag/jshint style=font-size:10px>JSHint</a><a href=../tag/java style=font-size:11.43px>Java</a><a href=../tag/javascript style=font-size:12.86px>JavaScript</a><a href=../tag/linux style=font-size:17.14px>Linux</a><a href=../tag/pdo style=font-size:10px>PDO</a><a href=../tag/php style=font-size:12.86px>PHP</a><a href=../tag/poi style=font-size:10px>POI</a><a href=../tag/photoshop style=font-size:14.29px>Photoshop</a><a href=../tag/sae style=font-size:10px>SAE</a><a href=../tag/sql style=font-size:14.29px>SQL</a><a href=../tag/sqlite style=font-size:11.43px>SQLite</a><a href=../tag/stl style=font-size:11.43px>STL</a><a href=../tag/stu3 style=font-size:10px>Stu3</a><a href=../tag/twitter style=font-size:10px>Twitter</a><a href=../tag/virtualbox style=font-size:10px>VirtualBox</a><a href=../tag/jquery style=font-size:10px>jQuery</a><a href=../tag/三国杀 style=font-size:15.71px>三国杀</a><a href=../tag/乌镇 style=font-size:10px>乌镇</a><a href=../tag/互联网 style=font-size:10px>互联网</a><a href=../tag/动漫 style=font-size:11.43px>动漫</a><a href=../tag/动画 style=font-size:10px>动画</a><a href=../tag/南京 style=font-size:14.29px>南京</a><a href=../tag/博客 style=font-size:14.29px>博客</a><a href=../tag/实验 style=font-size:15.71px>实验</a><a href=../tag/容器 style=font-size:11.43px>容器</a><a href=../tag/小说 style=font-size:10px>小说</a><a href=../tag/微博 style=font-size:11.43px>微博</a><a href=../tag/心情 style=font-size:14.29px>心情</a><a href=../tag/摄影 style=font-size:17.14px>摄影</a><a href=../tag/操作系统 style=font-size:14.29px>操作系统</a><a href=../tag/数据库 style=font-size:18.57px>数据库</a><a href=../tag/旅行 style=font-size:20px>旅行</a><a href=../tag/日记 style=font-size:17.14px>日记</a><a href=../tag/杭州 style=font-size:11.43px>杭州</a>
</div>
</div>
<div class="widget-wrap hidden-xs">
<h3 class=widget-title>归档</h3>
<div class=widget>
<ul class=archive-list><li class=archive-list-item><a class=archive-list-link href=../archive/2014/09>September 2014</a><span class=archive-list-count>4</span></li><li class=archive-list-item><a class=archive-list-link href=../archive/2014/08>August 2014</a><span class=archive-list-count>4</span></li><li class=archive-list-item><a class=archive-list-link href=../archive/2012/09>September 2012</a><span class=archive-list-count>1</span></li><li class=archive-list-item><a class=archive-list-link href=../archive/2012/05>May 2012</a><span class=archive-list-count>2</span></li><li class=archive-list-item><a class=archive-list-link href=../archive/2012/04>April 2012</a><span class=archive-list-count>5</span></li><li class=archive-list-item><a class=archive-list-link href=../archive/2012/03>March 2012</a><span class=archive-list-count>5</span></li><li class=archive-list-item><a class=archive-list-link href=../archive/2011/12>December 2011</a><span class=archive-list-count>4</span></li><li class=archive-list-item><a class=archive-list-link href=../archive/2011/11>November 2011</a><span class=archive-list-count>18</span></li><li class=archive-list-item><a class=archive-list-link href=../archive/2011/10>October 2011</a><span class=archive-list-count>32</span></li><li class=archive-list-item><a class=archive-list-link href=../archive/2011/05>May 2011</a><span class=archive-list-count>2</span></li></ul>
</div>
</div>
<div class="widget-wrap hidden-xs">
<h3 class=widget-title>友情链接</h3>
<div class=widget>
<ul>
<li>
<a href=http://cweili.gitcafe.com target=_blank>主页</a>
</li>
</ul>
</div>
</div>
</aside>
</div>
<footer id=footer>
<div class=footer-wrap>
<div class=outer>
<div class=inner>
<div id=social-network>
<a class=link href=https://github.com/Cweili target=_blank><i class="fa fa-fw fa-github"></i></a>
<a class=link href=http://weibo.com/cweili target=_blank><i class="fa fa-fw fa-weibo"></i></a>
</div>
<div id=footer-info>
&copy; 2014 <a href=http://cweili.gitcafe.com target=_blank>Cweili</a><br>
Powered by <a href="http://hexo.io/" target=_blank>Hexo</a>.
Theme by <a href=http://cweili.gitcafe.com target=_blank>Cweili</a>.
</div>
</div>
</div>
</div>
</footer>
</div>
</div>
<div id=rocket-to-top>
<div class=onhover></div>
<div class=anim></div>
</div>
<link rel=stylesheet href=//libs.baidu.com/fontawesome/4.0.3/css/font-awesome.min.css css type=text/css>
<script src=//libs.baidu.com/jquery/1.11.1/jquery.min.js type=text/javascript></script><link rel=stylesheet href=//cdn.staticfile.org/fancybox/2.1.5/jquery.fancybox.min.css type=text/css>
<script src=//cdn.staticfile.org/fancybox/2.1.5/jquery.fancybox.min.js type=text/javascript></script><script src=../js/script.js type=text/javascript></script><script type=text/javascript>var duoshuoQuery={short_name:"cweiligitcafe"};</script><script src=//static.duoshuo.com/embed.js type=text/javascript></script><script type=text/javascript>var ujian_config={num:10,showType:3};</script><script src="http://v1.ujian.cc/code/ujian.js?uid=1539214&_=.js" type=text/javascript></script><script type=text/javascript>window._bd_share_config={common:{bdSnsKey:{},bdPopTitle:"分享到",bdMini:2,bdPopupOffsetLeft:28,bdPopupOffsetTop:108,bdMiniList:["sqq","mshare","bdysc","kaixin001","ibaidu","baidu","ff","qy","meilishuo","mogujie","diandian","ty","youdao","sdo"],bdPic:"",bdStyle:1,bdSize:"24"},share:{},image:{viewList:["tsina","qzone","tqq","weixin","tieba","renren","tqf","douban","tsohu","t163","taobao","fx","hi"],viewText:" ",viewSize:"24"},selectShare:{bdContainerClass:"article",bdSelectMiniList:["tsina","qzone","tqq","weixin","tieba","renren","tqf","douban","tsohu","t163","taobao","fx","hi"]}},document.write('<script type="text/javascript" src="http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date/36e5)+'"><\/script>');</script><div id=stat-wrap>
<script src="http://s19.cnzz.com/stat.php?id=1252976445&web_id=1252976445" type=text/javascript></script></div></body></html>